<template>
  <div>
    <el-card>
      <el-row>

      </el-row>
    </el-card>
    <el-table
    
      :data="pushclass"
      tooltip-effect="dark"
      border
      header-align="center"
      style="width: 1600px">
      <!-- 索引列用index标识 -->
      <el-table-column label="序号" type="index" width="200"> </el-table-column>
      <el-table-column prop="name" label="分组名称" width="200">
      </el-table-column>
      <el-table-column prop="note" label="分组备注" width="200">
      </el-table-column>
      <el-table-column prop="subbranch" label="所属分店" width="200">
      </el-table-column>

      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="
              handleEdit(scope.$index, scope.row)
              dialogFormVisible = true">编辑</el-button>
          <el-dialog title="编辑分组：" :visible.sync="dialogFormVisible">
            <el-form :model="form">
              <el-form-item label="分组名称：" :label-width="formLabelWidth">
                <el-input v-model="form.name" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="分组备注：" :label-width="formLabelWidth">
                <el-input v-model="form.note" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="所属分店：" :label-width="formLabelWidth">
                <el-input v-model="form.subbranch" autocomplete="off"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible = false;editor()">确 定</el-button
              >
            </div>
          </el-dialog>

          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 下方卡片视图 -->
   <addclass/>

 
  </div>
</template>



<script>
import {getclassPost,delclassPost,editorclassPost}from '../../http/api';
import addclass from './addclass.vue'
export default {
  components: { addclass },
  methods: {
    //编辑按钮
    handleEdit(index, row) {
      console.log(index, row) 
      // 将这一行的值赋值给form
      this.form = row
    },
    handleDelete(index, row) {
      // 给删除按钮添加弹框
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!',
          })
          this.classdel.id = row.id
          console.log(index,this.classdel,'aaa')
          // 分组删除请求
            delclassPost(this.classdel)
                .then((res)=>{
                  console.log('分组删除成功',res)
                  // 删除后渲染列表
                  this.getlist()

                })
                .catch((err)=>{
                  console.log('分组删除失败',err)
                })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },
    // 列表获取函数
      getlist(){
       getclassPost()
        .then((res)=>{
          console.log('接口调用成功',res)
          this.pushclass = res.data.value.data
        })
        .catch((err)=>{
          console.log('接口调用失败',err)
        })
      },
      // 编辑分组
      editor(){
        console.log(this.form,"edddd")
        editorclassPost(this.form)
          .then((res)=>{
            console.log('分组编辑成功',res)
            // 编辑后渲染列表
            this.getlist()
          })
          .catch((err)=>{
            console.log('分组编辑失败',err)
          })

      }
  },
    //  开始前渲染
      created(){
        this.getlist()
    },
  data() {
    return {
      classdel:{id:''},
      // 表格的数据
      dialogFormVisible: false,
      form:[ {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
      }],
            // 添加分组
      pushclass:[{
        name:'',
        note:'',
        subbranch:''
      }],
      formLabelWidth: '120px',
    }
  },
}
</script>



<style lang="less" scoped>
.el-card {
  box-shadow: 0 0 0 rgb(0, 0, 0, 0.15);
}
.el-table-column {
  text-align: center;
}
</style>>
 
